# Contributor: Adrian Siekierka <kontakt@asie.pl>
# Maintainer: Thomas Kienlen <kommander@laposte.net>
pkgname=openttd
pkgver=14.1
pkgrel=0
pkgdesc="Open source version of the Transport Tycoon Deluxe simulator"
url="https://www.openttd.org"
arch="all"
license="GPL-2.0-or-later"
makedepends="
	cmake
	curl-dev
	fontconfig-dev
	fluidsynth-dev
	freetype-dev
	harfbuzz-dev
	icu-dev
	libpng-dev
	lzo-dev
	samurai
	sdl2-dev
	xz-dev
	zlib-dev
	"
subpackages="$pkgname-doc $pkgname-lang::noarch"
source="https://cdn.openttd.org/openttd-releases/$pkgver/openttd-$pkgver-source.tar.xz
	no-sse4.patch
	"

build() {
	cmake -B build \
		-G "Ninja" \
		-DCMAKE_INSTALL_BINDIR=bin \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_DATADIR=share/games \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS -Wl,-z,stack-size=1048576"
	cmake --build build
}

check() {
	cmake --build build --target openttd_test
	./build/openttd_test
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
}

lang() {
	pkgdesc="$pkgdesc (localizations)"

	cd "$pkgdir"
	mkdir -p "$subpkgdir"/usr/share/games/openttd/lang
	find usr/share/games/openttd/lang/ ! -name 'english.lng' -type f \
		-exec mv {} "$subpkgdir"/{} \;
}

sha512sums="
194135cc01457d9ed069c09d8961ad3de681bc9936533ca81ff23099f394bb9a83ef84a0852e85525e258f6149e14fd41cfc5f8e683c0643515005c42fb77e3b  openttd-14.1-source.tar.xz
fef70a685b4d440a0c1a6b6cde94df2dcada7ee10f4b213ee0a649dfbbb5de800aed06a4f066b2be5369147b1ecd83ad6b89bdb06138c46b250ca7f75c95b5a4  no-sse4.patch
"
